#include"tcpserver.hpp"
#include"protocol.hpp"
#include"Http.hpp"
//#include"NetCal.hpp"
//创建一个服务函数
void Login(HttpRequest& req,HttpResopnse& resp)
{
    std::string message="hello"+req.GetArgs();
    std::cout << "AAAAAAAAAAAAAAAAAAAAAAAAAA\n";
    std::cout << message << std::endl;
    LOG(LogLevel::DEBUG)<<req.GetArgs()<<"被受理###############################################";
    resp.SetText(message);
    resp.SetCode(200);
    resp.SetHeader("Content-Type","text/plain");//纯文本
    resp.SetHeader("Content-Length",std::to_string(message.size()));
}
int main(int argc,char* argv[])
{
    //格式:./main port
    if(argc!=2)
    {
        //格式输入错误
        std::cout<<"格式输入错误,应该为:./main port"<<std::endl;
        exit(0);
    }
    uint16_t port=std::stoi(argv[1]);
    std::unique_ptr<Http> httpsvr=std::make_unique<Http>(port);
    httpsvr->SetHeader("/login",Login);
    httpsvr->Start();
    // std::unique_ptr<NetCal> n=std::make_unique<NetCal>();
    // std::unique_ptr<Protocol> p=std::make_unique<Protocol>([&n](Request& q)->Response{return n->Handler(q);});
    // std::unique_ptr<tcpserver> t=std::make_unique<tcpserver>(std::stoi(argv[1]),
    //     [&p](std::shared_ptr<Socket>& sock,Addr& client)
    //     {
    //         p->GetRequest(sock,client);
    //     });
    // t->Start();
    return 0;
}